﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using MobileWeb.Helpers;
using MobileWeb.Models;

namespace MobileWeb.Controllers
{
    public class TrazilicaController : Controller
    {
        //
        // GET: /Trazilica/
        public ActionResult Index()
        {
            var model = new SearchModel()
            {
                Areas = IntervalHelper.GetAreas(),
                Floors = IntervalHelper.GetFloors(),
                Apartments = SearchHelper.GetApartments("sve", "sve")
            };

            var area = new Area() {Id = Int32.MinValue, Name = "sve"};
            model.Areas.Insert(0, area);
            model.SelectedArea = Int32.MinValue;

            var floor = new Floor() {Id = Int32.MinValue, Name = "sve"};
            model.Floors.Insert(0, floor);
            model.SelectedFloor = Int32.MinValue;

            ViewBag.TitleImg = "/Content/Images/TitleTrazilica.png";
            return View(model);
        }

        //
        // POST : /Trazilica/ 
        [HttpPost]
        public ActionResult Index(SearchModel searchModel)
        {
            var selectedArea = searchModel.SelectedArea == Int32.MinValue ? "sve" : searchModel.SelectedArea.ToString();
            var selectedFloor = searchModel.SelectedFloor == Int32.MinValue ? "sve" : searchModel.SelectedFloor.ToString();

            var model = new SearchModel()
            {
                Areas = IntervalHelper.GetAreas(),
                Floors = IntervalHelper.GetFloors(),
                Apartments = SearchHelper.GetApartments(selectedArea, selectedFloor)
            };

            var area = new Area() { Id = Int32.MinValue, Name = "sve" };
            model.Areas.Insert(0, area);
            model.SelectedArea = Int32.MinValue;

            var floor = new Floor() { Id = Int32.MinValue, Name = "sve" };
            model.Floors.Insert(0, floor);
            model.SelectedFloor = Int32.MinValue;

            searchModel = model;

            ViewBag.TitleImg = "/Content/Images/TitleTrazilica.png";
            return View(searchModel);
        }



    }
}
